package com.ckv.qcm.jdbc;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class SQLServerConnection {

	private static InitialContext context;
	private static Connection connection;

	public static Connection getInstance() {

		try {
			context = new InitialContext();
			DataSource ds = (DataSource) context
					.lookup("java:comp/env/jdbc/QCM");
			connection = ds.getConnection();
		} catch (NamingException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return connection;
	}

	public static void close() {
		try {
			connection.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
